package com.fc.authentication.common.xss;

import com.fc.authentication.common.dto.Result;
import com.fc.authentication.common.exception.RRException;
import com.fc.authentication.common.utils.HttpContextUtils;
import com.fc.authentication.common.utils.IPUtils;
import com.fc.authentication.core.migrate.utils.StringUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import static com.fc.authentication.common.utils.JsonUtils.out;

/**
 * Created by Sunny on 2018/6/20.
 */
public class FcFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
        System.out.println(IPUtils.getIpAddr(request));
        //TODO
        if(false)
        {

           out((HttpServletResponse)servletResponse, Result.error("500","非法操作" ));
           return;
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
